#region File Description
//-----------------------------------------------------------------------------
// TestGameGame.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;

#endregion

namespace TestGame
{
	/// <summary>
	/// Default Project Template
	/// </summary>
	public class Game1 : Game
	{

	#region Fields
		GraphicsDeviceManager graphics;
		SpriteBatch spriteBatch;
		Texture2D Building;
		Texture2D BuildingTop;
	#endregion

	#region Initialization

        public Game1()  
        {

			graphics = new GraphicsDeviceManager(this);
			graphics.PreferredBackBufferHeight = 640;
			graphics.PreferredBackBufferWidth = 800;
			graphics.IsFullScreen = false;
			IsMouseVisible = true;
			Window.Title = "Test Game Window";
			graphics.ApplyChanges ();

			Content.RootDirectory = "Content";
		}

		/// <summary>
		/// Overridden from the base Game.Initialize. Once the GraphicsDevice is setup,
		/// we'll use the viewport to initialize some values.
		/// </summary>
		protected override void Initialize()
		{
			Camera cam = new Camera (GraphicsDevice);
			cam.Position = new Vector2 (0, 0);
			cam.MakeActive ();
			base.Initialize();
		}


		/// <summary>
		/// Load your graphics content.
		/// </summary>
		protected override void LoadContent()
		{
			// Create a new SpriteBatch, which can be use to draw textures.
			spriteBatch = new SpriteBatch(GraphicsDevice);

			Building = Content.Load<Texture2D> (@"Buildings/std_base");
			BuildingTop = Content.Load<Texture2D> (@"Buildings/std_top");
		}

	#endregion

	#region Update and Draw

		/// <summary>
        	/// Allows the game to run logic such as updating the world,
        	/// checking for collisions, gathering input, and playing audio.
        	/// </summary>
        	/// <param name="gameTime">Provides a snapshot of timing values.</param>
		protected override void Update(GameTime gameTime)
		{
			Camera.m_Active.Update (gameTime);
			if (Keyboard.GetState ().IsKeyDown (Keys.Escape))
				Exit ();
			if (Keyboard.GetState ().IsKeyDown (Keys.Left))
				Camera.m_Active.Move (new Vector2 (-5, 0));
			if (Keyboard.GetState ().IsKeyDown (Keys.Right))
				Camera.m_Active.Move (new Vector2 (5, 0));
			if (Keyboard.GetState ().IsKeyDown (Keys.Up))
				Camera.m_Active.Move (new Vector2 (0, 5));
			if (Keyboard.GetState ().IsKeyDown (Keys.Down))
				Camera.m_Active.Move (new Vector2 (0, -5));
            		
			base.Update(gameTime);
		}

		/// <summary>
		/// This is called when the game should draw itself. 
		/// </summary>
		/// <param name="gameTime">Provides a snapshot of timing values.</param>
		protected override void Draw(GameTime gameTime)
		{
			// Clear the backbuffer
			graphics.GraphicsDevice.Clear(Color.White);

			//spriteBatch.Begin();
			spriteBatch.Begin (SpriteSortMode.FrontToBack, BlendState.AlphaBlend,null,null,RasterizerState.CullNone,null,Camera.m_Active.GetTransform);

			// draw the logo
			spriteBatch.Draw(Building, new Vector2 (0, BuildingTop.Height), Color.White);
			spriteBatch.Draw(BuildingTop, new Vector2 (0, 0), Color.White);
			spriteBatch.Draw(Building, new Vector2 (32, BuildingTop.Height), Color.White);
			spriteBatch.Draw(BuildingTop, new Vector2 (32, 0), Color.White);
			spriteBatch.Draw(Building, new Vector2 (64, BuildingTop.Height), Color.White);
			spriteBatch.Draw(BuildingTop, new Vector2 (64, 0), Color.White);

			spriteBatch.End();

			base.Draw(gameTime);
		}

	#endregion
	}
}
